package ru.acme.lab16.service.bank;

import ru.acme.lab16.domain.account.Account;
import ru.acme.lab16.domain.account.ImmutableAccount;
import ru.acme.lab16.domain.bank.Bank;
import ru.acme.lab16.domain.bank.ImmutableBank;
import ru.acme.lab16.domain.client.Client;
import ru.acme.lab16.domain.client.ClientRegistrationListener;
import ru.acme.lab16.domain.client.ImmutableClient;

public class BankService {
	
	public static void addClient(Bank bank, Client client) {
		bank.addClient(client);
	}
	
	public static void modifyBank(Bank bank) {
		for (Client client : bank.getClients()) {
			for (Account account : client.getAccounts()) {
				if (Math.random() > 0.5) {
					account.deposit((int)(100 * Math.random()));
				} else {
					account.withdraw((int)(100 * Math.random()));
				}
			}
		}		
	}

	public static void printBalances(ImmutableBank bank) {
		for (ImmutableClient client : bank.getImmutableClients()) {
			for (ImmutableAccount account : client.getImmutableAccounts()) {
				System.out.print(account.getBalance() + " ");
			}
		}
		System.out.println();
	}

	public static void printMaximumAmountsToWithdraw(ImmutableBank bank) {
		for (ImmutableClient client : bank.getImmutableClients()) {
			for (ImmutableAccount account : client.getImmutableAccounts()) {
				System.out.print(account.maximumAmountToWihdraw() + " ");
			}
		}
		System.out.println();
	}

	public static void addListener(Bank bank, ClientRegistrationListener listener) {
		bank.addListener(listener);
	}
}
